package com.gangan.controller.web;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.controller.common.BaseController;
import com.gangan.model.Ad;
import com.gangan.model.AdCate;
import com.gangan.service.IAdService;
import com.gangan.tools.MessageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-09-04
 */
@Api(description = "*轮播图分类模块控制层")
@RestController
@RequestMapping("/ad")
public class AdController extends BaseController {

    @Autowired
    IAdService adService;

    @RequestMapping(value = "/findAdByCateId",method = RequestMethod.GET)
    @ApiOperation(value="轮播图数据", notes="根据轮播图分类自增主键查找出所有该主键下所有轮播图")
    public MessageBean findAdByCateId(Integer cateId){
        return resultSuccess(adService.list(Wrappers.<Ad>query().lambda().eq(Ad::getCateId,cateId)));
    }

    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ApiOperation(value="移除轮播图", notes="根据自增主键移除数据")
    public MessageBean del(Integer id){
        return resultSuccess(adService.removeById(id));
    }
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value="新增轮播图", notes="将提交的数据保存到数据库")
    public MessageBean add(Ad add){
        return resultSuccess(adService.save(add));
    }

    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ApiOperation(value="编辑轮播图", notes="根据主键修改数据")
    public MessageBean edit(Ad edit){
        return resultSuccess(adService.updateById(edit));
    }
}
